﻿Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports VSModel

Imports System.Web.Script.Services
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Converters
Imports System.Web.Script.Serialization

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class KhachTroService
     Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As String
        Return "Hello World"
    End Function

     <WebMethod()> _
     Public Function GetListCustomers() As String
          Try
               Using data As New VSEntities
                    Dim _lst = (From q In data.uspGetListCustomersSyn).ToList()
                    Dim serializer As New JsonSerializer
                    serializer.Converters.Add(New JavaScriptDateTimeConverter())
                    serializer.NullValueHandling = NullValueHandling.Ignore
                    Dim sJSON As String = JsonConvert.SerializeObject(_lst)
                    Return sJSON
               End Using
          Catch ex As Exception
               Return ""
          End Try
     End Function

     <WebMethod()> _
     Public Function UpdateListCustomers(ByVal _lstCusID As String) As Boolean
          Try
               Using data As New VSEntities
                    Dim _lstID = _lstCusID.Split(",")
                    '' Update Customer in ListID 
                    Dim _lst = (From q In data.Customers
                               Where _lstID.Contains(q.CustomerId)).ToList()
                    For Each item In _lst
                         item.FlagUpdate = 1
                    Next
                    data.SaveChanges()
               End Using
               Return True
          Catch ex As Exception
               Return False
          End Try
     End Function
End Class